package com.ocom.mqsimple.controller;

import com.alibaba.fastjson.JSON;
import com.ocom.common.constant.MqSimpleApiUrl;
import com.ocom.common.entity.company.EntityComDockApi;
import com.ocom.common.entity.mjrecode.MjRecord;
import com.ocom.common.enums.DockApiCodeEnum;
import com.ocom.common.enums.ResultEnum;
import com.ocom.common.enums.ssgl.SSGLMqTypeEnum;
import com.ocom.common.request.company.GetComRequestRequest;
import com.ocom.common.request.simple.ssgl.SSGLAccessRecordRequest;
import com.ocom.common.request.simple.ssgl.SSGLMqBaseRequest;
import com.ocom.common.request.simple.ssgl.SSGLNewPersonInfoRequest;
import com.ocom.common.request.srvpaccess.GetNosendRecordRequest;
import com.ocom.common.resp.Result;
import com.ocom.common.response.GetComRequestResponse;
import com.ocom.common.utils.DateUtil;
import com.ocom.common.utils.DateUtils;
import com.ocom.common.utils.ResultUtil;
import com.ocom.mqsimple.business.ssgl.impl.SSGLProductServiceImpl;
import com.ocom.mqsimple.business.wgkq.impl.WGKQProductServiceImpl;
import com.ocom.mqsimple.feign.CompanyClientService;
import com.ocom.mqsimple.feign.MjrecodeClientService;
import com.ocom.redis.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@RestController
@Slf4j
public class WGKQController {

	private final Logger logger = LoggerFactory.getLogger(WGKQController.class);

	@Autowired
	private WGKQProductServiceImpl productService;
	@Autowired
	private CompanyClientService companyClientService;

	@PostMapping(MqSimpleApiUrl.URL_wgkqMqNewPersonInfo)
	public Result newPersonInfo(@RequestBody SSGLNewPersonInfoRequest request){
		try {
			log.info("newPersonInfo=====参数：【{}】", request);
			SSGLMqBaseRequest baseRequest = new SSGLMqBaseRequest();

//			baseRequest.setType(SSGLMqTypeEnum.NEW_PERSONINFO.getValue());

			String dockApiCode = DockApiCodeEnum.wgkq_newPersonInfo.getValue();
			Result comDockApiResult = companyClientService.getComDockApi("wgkq", request.getComId(),dockApiCode, 1);
			EntityComDockApi entityComDockApi = JSON.parseObject(JSON.toJSONString(comDockApiResult.getData()), EntityComDockApi.class);

			if (null != entityComDockApi && 0 < entityComDockApi.getAutoSize()) {
				request.setAutoSize(entityComDockApi.getAutoSize());
			}
			baseRequest.setMessage(JSON.toJSONString(request));
			productService.handle(JSON.toJSONString(baseRequest));
		}catch (Exception e){
			logger.error("发送mq失败  错误【{}】",e);
			return ResultUtil.error(ResultEnum.Err_4006);
		}
		return ResultUtil.success();
	}

}
